package com.java.controller;

import com.java.pojo.EnterGood;
import com.java.pojo.Page;
import com.java.pojo.Tracking;
import com.java.service.TrackingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/Tracking")
public class TrackingController {

    @Autowired
    private TrackingService trackingService;

    @RequestMapping("/findAllByTr")
    public String findTR(@RequestParam(value = "start",required = false) Integer start, @RequestParam(value = "document1",required = false)String document1 , Model model){
        if(document1==null ||"".equals(document1)){
            document1="";
        }
        if(start==null ||start.equals("")){
            start=1;
        }
        System.out.println(start+"+"+document1);
        /*计算总页数*/
        int totalCount = trackingService.getCountTR(document1);
        int i = totalCount % 4 ==0? totalCount/4 :(totalCount/4)+1;
        /*如果最后一页大于总页数,就让其等于总页数,html按钮最后一页
         * 如果前一页到0的时候,把他变成1*/
        if(start>=i){
            start=i;
        }else if(start<=1){
            start=1;
        }
        Page<Tracking> page =trackingService.getPageByTR(start,document1);
        System.out.println("page:"+page);
        model.addAttribute("page",page);
        model.addAttribute("document1",document1);

        return "Tracking/findAllByTR";
    }


}
